import time
from selenium.webdriver.common.by import By
from common.Utils import FroumDriver

class FroumPCenter:
    driver = ""
    url = ""
    def __init__(self):
        self.driver = FroumDriver.driver
        #添加 隐式等待
        self.driver.implicitly_wait(5)
        self.url = "http://127.0.0.1:9580/index.html"
        self.driver.get(self.url)

    # 测试个人中心页元素
    def PCenterTest(self):
        # 登录状态下，通过用户中心的url访问，只能访问到论坛首页，不能进入用户中心页，这里利用点击进入用户中心页
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_settings").click()
        #检查用户头像
        self.driver.find_element(By.CSS_SELECTOR,"#settings_avatar")
        #检查用户名
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname")
        #检查邮箱地址
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email")
        #检查电话号码
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum")
        #屏幕截图
        time.sleep(1)
        FroumDriver.getScreenShot()

    #测试 修改密码功能
    def ChangePasswordTest(self):
        # 登录状态下，通过用户中心的url访问，只能访问到论坛首页，不能进入用户中心页，这里利用点击进入用户中心页
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()
        #输入“原密码” “新原密码” “确认密码”
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123")
        #点击 “提交修改”
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()
        #测试是否跳转登录界面，且输入框为空
        self.driver.find_element(By.CSS_SELECTOR, "#submit")
        text1=self.driver.find_element(By.CSS_SELECTOR, "#username").text
        test2=self.driver.find_element(By.CSS_SELECTOR, "#password").text
        username=""
        password=""
        assert text1==username and test2==password
        time.sleep(1)
        FroumDriver.getScreenShot()










